﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Option.Master" AutoEventWireup="true"
    CodeBehind="SelectUser.aspx.cs" Inherits="MsgCenter.Web.Pages.User.SelectUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="headContent" runat="server">
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/ace.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/ace-extra.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/bootstrap.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/ace-elements.min.js") %>"></script>
    <link rel="stylesheet" media="screen" type="text/css" href="<%=ResolveClientUrl("~/JavaScript/Tree/tree.css") %>" />
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/Tree/tree.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/i18n/grid.locale-cn.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/jquery.jqGrid.min.js") %>"></script>
    <script type="text/javascript" src="<%=ResolveClientUrl("~/JavaScript/FirePlat/assets/js/jqGrid/myJqgrid.js") %>"></script>
    <script type="text/javascript">
        function getCalendarData() {
            var trdata = null;
            $.ajax({
                type: "GET",
                url: "../../Handlers/Handler_Dept.ashx?method=GetDeptTree",
                async: false,
                success: function (msg)
                { trdata = msg; },
                error: function (msg) { }
            });
            return trdata;
        }
        function LoadTree() {
            var o = {
                cbiconpath: "../../Images/tree/",
                emptyiconpath: "../../Images/tree/s.gif",
                showcheck: false,
                onnodeclick: function (item) {
                    var deptID = "";
                    if (item.value != "00000000-0000-0000-0000-000000000000" && item.id != "000001") {
                        deptID = item.value;
                    }
                    SetArrayNewList();
                    $("#" + gridTableID).jqGrid('setGridParam', {
                        postData: { 'DeptGuID': deptID }, //发送数据  
                        page: 1
                    }).trigger("reloadGrid"); //重新载入
                }
            };
            var tre = getCalendarData();
            eval("var data =" + tre + ";");
            o.data = data;
            $("#tree").treeview(o);
        }
        $(document).ready(function () {
            LoadTree();
        });

        var gridTableID = 'grid-table';
        var gridPagerID = 'grid-pager';
        var ajaxUrl = "../../Handlers/Handler_User.ashx";
        jQuery(function ($) {
            var url = ajaxUrl + "?method=GetUserALLList";
            var colNames = ['UserID','工号', '用户名称', '所属部门'];
            var colModel = [
				{ name: 'UserID', index: 'UserID', width: 50, editable: false, hidden: true },
				{ name: 'Code', index: 'Code', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'Name', index: 'Name', width: 12, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} },
				{ name: 'DeptName', index: 'DeptName', width: 30, editable: false, stype: 'text', searchoptions: { sopt: ['eq', 'ne', 'cn', 'nc']} }
			];
            var dfop =
            {
                rownumbers: true,
                GridID: gridTableID,
                GridPagerID: null,
                Url: url,
                ColNames: colNames,
                ColModel: colModel,
                Caption: "用户列表",
                SortName: "DeptName",
                SortOrder: "asc",
                Height: 400,
                RowNum: 2000,
                GridComplete: GridComplete
            };
            showJqGrid(dfop);
        });
        function Reload() {
            $("#" + gridTableID).trigger("reloadGrid");
        }

        //新建一个数组，存放已勾选的id
        var arrayNewList = new Array();
        function SetArrayNewList() {
            var rowIds = jQuery("#" + gridTableID).jqGrid('getDataIDs');
            var ids = $('#' + gridTableID).jqGrid('getGridParam', 'selarrrow');
            if (rowIds != "") {
                for (var i = 0; i < rowIds.length; i++) {
                    var rowData = $('#' + gridTableID).jqGrid('getRowData', rowIds[i]);
                    for (var a = 0; a < arrayNewList.length; a++) {
                        if (arrayNewList[a].UserID == rowData.UserID) {
                            arrayNewList.splice(a, 1);
                            break;
                        }
                    }
                }
                if (ids != "") {
                    for (var i = 0; i < ids.length; i++) {
                        var rowData = $('#' + gridTableID).jqGrid('getRowData', ids[i]);
                        arrayNewList.push(rowData);
                    }
                }
            }
        }


        function GridComplete() {
            var arrayLength = arrayNewList.length;
            if (arrayLength > 0) {
                var rowIds = jQuery("#" + gridTableID).jqGrid('getDataIDs');
                if (rowIds != "") {
                    for (var i = 0; i < rowIds.length; i++) {
                        var rowData = $('#' + gridTableID).jqGrid('getRowData', rowIds[i]);
                        for (var a = 0; a < arrayLength; a++) {
                            if (arrayNewList[a].UserID == rowData.UserID) {
                                $("#" + gridTableID).jqGrid('setSelection', (i + 1));
                                break;
                            }
                        }
                    }
                }
            }
        }

        function SelectUserAdd() {
            SetArrayNewList();
            var arrayLength = arrayNewList.length;
            if (arrayLength == 0) {
                showDialogMessage("请先选择接收人员!");
                return false;
            }
            var userid = "";
            var username = "";
            for (var a = 0; a < arrayLength; a++) {
                if (username == "") {
                    username = arrayNewList[a].Name;
                    userid = username + "&" + arrayNewList[a].UserID;
                }
                else {
                    username = username + "," + arrayNewList[a].Name;
                    userid = userid + "," + arrayNewList[a].Name + "&" + arrayNewList[a].UserID;
                }
            }
            parent.SetSelectUser(username, userid);
            CloseBox();
            return false;
        }
        function CloseBox() {
            parent.CBClose();
        }
        function SelectGroupUser() {
            window.location = "../UserGroup/SelectGroupUser.aspx";
            return false;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="mailContent" runat="server">
    <div class="row">
        <div class="col-xs-3">
            <div class="widget-box">
                <div class="widget-header header-color-blue2">
                    <h4 class="lighter smaller">
                        部门列表</h4>
                </div>
                <div class="widget-body">
                    <div class="widget-main padding-8">
                        <div id="tree" style="height: 400px; overflow-x: no; overflow-y: auto;">
                            <img src="../../Images/tree/loading.gif" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-xs-7">
            <div class="row">
                <div class="col-xs-12">
                    <table id="grid-table">
                    </table>
                </div>
            </div>
        </div>
        <div class="col-xs-2">
            <div class="widget-box">
                <div class="widget-header header-color-blue2">
                    <h4 class="lighter smaller">
                        功能操作</h4>
                </div>
                <div class="widget-body">
                    <div class="widget-main padding-8" style="height: 415px">
                        <br />
                        <br />
                        <div class="row">
                            <div class="col-xs-12">
                                <button class="btn btn-sm btn-primary" onclick="return SelectGroupUser();">
                                    <i class="icon-edit bigger-110"></i>按组选择 <i class="icon-arrow-right icon-on-right">
                                    </i>
                                </button>
                                <br />
                                <br />
                                <br />
                                <br />
                                <br />
                                <br />
                                <button class="btn btn-sm btn-success" onclick="return SelectUserAdd();">
                                    <i class="icon-ok bigger-110"></i>添加人员 <i class="icon-arrow-right icon-on-right">
                                    </i>
                                </button>
                                <br />
                                <br />
                                <br />
                                <br />
                                <br />
                                <br />
                                <button class="btn btn-danger btn-block" onclick="return CloseBox();">
                                    关闭窗体</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</asp:Content>
